""" 1_1 联网功能 """
# https://learn.adafruit.com/adafruit-esp32-s3-tft-feather/circuitpython-internet-test

import ssl
import wifi
import socketpool
import adafruit_requests	# 需要安装扩展
import time

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
# TEXT_URL = "https://honestqiao.gitee.io/web_esptool/"

print("ESP32-S3 网络功能测试")
print("开发板MAC地址:", [hex(i) for i in wifi.radio.mac_address])
while not wifi.radio.connected:
    print("开发板正在联网...")
    time.sleep(1)

print("开发板已连接到WiFi")
print("开发板IP地址", wifi.radio.ipv4_address)

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

print("网络请求网址", TEXT_URL)
response = requests.post(TEXT_URL)
print("请求返回内容")
print("-" * 40)
print(response.text)
print("-" * 40)

print("测试完成")
